/**
 * @param {*} base64 图片base64
 */
export function base64ToImg (base64) {
    return new Promise((resolve, reject) => {
        const img = new Image()
        img.src = 'data:image/jpeg;base64,' + base64
        img.onload = function () {
            resolve(img)
        }
        img.onerror = function (e) {
            reject(e)
        }
    })
}

/**
 * @param {*} image
 */
export function imgToBase64(image) {
    var canvas = document.createElement("canvas");
    canvas.width = image.width;
    canvas.height = image.height;
    var ctx = canvas.getContext("2d");
    ctx.drawImage(img, 0, 0, image.width, image.height);
    var dataURL = canvas.toDataURL("image/png");
    return dataURL;
}
